/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.seagate.util.db;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.NamingException;
import oracle.jdbc.pool.OracleDataSource;
import oracle.jdbc.pool.OracleConnectionCacheManager;
//import org.jboss.resource.adapter.jdbc.WrappedConnection;

import java.util.Properties;
import java.sql.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

/**
 *
 * @author 407893
 */
public class OracleConnectionPool {

  /**
   * private constructor for static class
   */
  public OracleConnectionPool() {
    
  }//end method

  public static Connection getConnection()
          throws SQLException {
    try {
      Context ctx = new InitialContext();
      DataSource ods = null;
      ods = (DataSource)ctx.lookup("java:/TT_ODS_REPORT");
      if (ods == null) {
        throw new SQLException("OracleDataSource is null.");
      }
      return ods.getConnection();
    } catch (NamingException ex) {
      return null;
    }
  }//end method

  public static Connection getConnectionOds()
          throws SQLException {
    try {
      Context ctx = new InitialContext();
      DataSource ods = null;
      ods = (DataSource)ctx.lookup("java:/TT_ODS_REPORT");
      if (ods == null) {
        throw new SQLException("OracleDataSource is null.");
      }
      return ods.getConnection();
    } catch (NamingException ex) {
      return null;
    }
  }//end method

  public static Connection getConnectionD2d()
          throws SQLException {
    try {
      Context ctx = new InitialContext();
      DataSource ods = null;
      ods = (DataSource)ctx.lookup("java:/TTD2D_CONFIG");
      if (ods == null) {
        throw new SQLException("OracleDataSource is null.");
      }
      return ods.getConnection();
    } catch (NamingException ex) {
      return null;
    }
  }//end method

//  public static void closePooledConnections() throws SQLException {
//    if (ods != null) {
//      //ods.close();
//      ods.getConnection().close();
//    }
//    if (d2d != null) {
//      d2d.close();
//    }
//  }//end method

//  public static void listCacheInfos() throws SQLException {
//    OracleConnectionCacheManager occm =
//            OracleConnectionCacheManager.getConnectionCacheManagerInstance();
//    System.out.println(occm.getNumberOfAvailableConnections(CACHE_NAME) + " connections are available in cache " + CACHE_NAME);
//    System.out.println(occm.getNumberOfActiveConnections(CACHE_NAME) + " connections are active");
//
//  }//end method
}//end class
